package com.cyy.partner.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author: cyy
 * @Date: 2024/5/22
 * 验证信息是否合法
 */
public class ValidatorUtil {
    /**
     * 判断手机号码是否正确
     * @param phoneNumber
     * @return
     */
    public static boolean isPhoneNumberValid(String phoneNumber){
        String regex = "^1(3[0-9]|4[5-9]|5[0-35-9]|6[5-6]|7[0-8]|8[0-9]|9[1-35-9])\\d{8}$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(phoneNumber);
        return matcher.matches();
    }

    /**
     * 判断邮箱是否正确
     * @param emailNumber
     * @return
     */
    public static boolean isEmailNumberValid(String emailNumber){
        String regex = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(emailNumber);
        return matcher.matches();
    }
}
